package com.yqh;

import com.yqh.utils.zookeeper.ZookeeperNode;
import com.yqh.utils.zookeeper.ZookeeperUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.zookeeper.*;

import java.util.List;


/**
 * 注册中心的管理页面
 *
 * @author 阳秋豪
 * @createTime 2024/2/29
 */
@Slf4j
public class Application {
    public static void main(String[] args) {
        // 创建一个 zookeeper 实例
        ZooKeeper zookeeper = ZookeeperUtils.createZookeeper();

        // 定义节点路径与节点数据
        ZookeeperNode BaseNode = new ZookeeperNode("/myrpc-metadata", null);
        ZookeeperNode providerNode = new ZookeeperNode(BaseNode.getPath() + "/providers", null);
        ZookeeperNode consumerNode = new ZookeeperNode(BaseNode.getPath() + "/consumers", null);

        // 创建节点
        List.of(BaseNode, providerNode, consumerNode).forEach(zookeeperNode -> {
            ZookeeperUtils.createNode(zookeeper, zookeeperNode, null, CreateMode.PERSISTENT);
        });

        // 关闭 zookeeper 实例
        ZookeeperUtils.closeZookeeper(zookeeper);
    }
}


